import { createRouter, createWebHashHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import NextLoading from '../assets/loading'


const router =  createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            name: 'Home',
            redirect: 'Index',
            meta: {
                isParent:true
            }
        },
        {
            path: '/index',
            name: 'Index',
            redirect: '/home',
            component: () => import('../views/Home/index.vue'),
            meta: {
                isParent:true
            },
            children: [
                {
                    path: '/404',
                    name: 'PageNotFound',
                    component: () => import('../views/Error/404.vue')
                },
                {
                    path: '/502',
                    name: 'BadGateway',
                    component: () => import('../views/Error/502.vue')
                },
                {
                    path: '/home',
                    name: 'MainHome',
                    component: () => import('../views/Home/home.vue')
                },
                {
                    path: '/blog',
                    name: 'Blog',
                    component: () => import('../views/Blog/index.vue')
                },
                {  
                    path: '/ie',
                    name: 'IE',
                    component: ()=> import('../views/IE/index.vue')
                },
                {  
                    path: '/resume',
                    name: 'Introduction',
                    component: ()=> import('../views/About/Introduction.vue')
                },
                {  
                    path: '/developer',
                    name: 'Developer',
                    component: ()=> import('../views/About/Developer.vue')
                },
                {
                    path: '/leave',
                    name: 'Leave',
                    component: ()=>import('../views/Leave/index.vue')
                }
              
            ]
        },
        {
            path: '/login',
            name: 'Login',
            meta: {
                isParent:true
            },
            component: () => import('../views/Login/index.vue')
        },
    ]
})

router.beforeEach((to, from, next) => {
  if(to.path=='/login'||to.path=='/home'){
    NextLoading.start()
  }else{
    NProgress.start()
  }
  next();
})

router.afterEach(() => {
    NextLoading.done()
    NProgress.done()
})


export default router